﻿#region Using directives

using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using NetROS.Tiers.Entities;
using NetROS.Tiers.Data;

#endregion

namespace NetROS.Tiers.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="VwSKPoDokumentimaPoTipuProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract class VwSKPoDokumentimaPoTipuProviderBaseCore : EntityViewProviderBase<VwSKPoDokumentimaPoTipu>
	{
		#region Custom Methods
		
		
		#region _vwSKPoDokumentimaPoTipu_GetByIDokument
		
		/// <summary>
		///	This method wrap the '_vwSKPoDokumentimaPoTipu_GetByIDokument' stored procedure. 
		/// </summary>
		/// <param name="IDDokument"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwSKPoDokumentimaPoTipu&gt;"/> instance.</returns>
		public VList<VwSKPoDokumentimaPoTipu> GetByIDokument(System.Int32? @IDDokument)
		{
			return GetByIDokument(null, 0, int.MaxValue , @IDDokument);
		}
		
		/// <summary>
		///	This method wrap the '_vwSKPoDokumentimaPoTipu_GetByIDokument' stored procedure. 
		/// </summary>
		/// <param name="IDDokument"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwSKPoDokumentimaPoTipu&gt;"/> instance.</returns>
		public VList<VwSKPoDokumentimaPoTipu> GetByIDokument(int start, int pageLength, System.Int32? @IDDokument)
		{
			return GetByIDokument(null, start, pageLength , @IDDokument);
		}
				
		/// <summary>
		///	This method wrap the '_vwSKPoDokumentimaPoTipu_GetByIDokument' stored procedure. 
		/// </summary>
		/// <param name="IDDokument"> A <c>System.Int32?</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <returns>A <see cref="VList&lt;VwSKPoDokumentimaPoTipu&gt;"/> instance.</returns>
		public VList<VwSKPoDokumentimaPoTipu> GetByIDokument(TransactionManager transactionManager, System.Int32? @IDDokument)
		{
			return GetByIDokument(transactionManager, 0, int.MaxValue , @IDDokument);
		}
		
		/// <summary>
		///	This method wrap the '_vwSKPoDokumentimaPoTipu_GetByIDokument' stored procedure. 
		/// </summary>
		/// <param name="IDDokument"> A <c>System.Int32?</c> instance.</param>
		/// <param name="start">Row number at which to start reading.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		/// <returns>A <see cref="VList&lt;VwSKPoDokumentimaPoTipu&gt;"/> instance.</returns>
		public abstract VList<VwSKPoDokumentimaPoTipu> GetByIDokument(TransactionManager transactionManager, int start, int pageLength , System.Int32? @IDDokument);
		
		#endregion
		
		#endregion

		#region Helper Functions
		
		/*
		///<summary>
		/// Fill an VList&lt;VwSKPoDokumentimaPoTipu&gt; From a DataSet
		///</summary>
		/// <param name="dataSet">the DataSet</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList&lt;VwSKPoDokumentimaPoTipu&gt;"/></returns>
		protected static VList&lt;VwSKPoDokumentimaPoTipu&gt; Fill(DataSet dataSet, VList<VwSKPoDokumentimaPoTipu> rows, int start, int pagelen)
		{
			if (dataSet.Tables.Count == 1)
			{
				return Fill(dataSet.Tables[0], rows, start, pagelen);
			}
			else
			{
				return new VList<VwSKPoDokumentimaPoTipu>();
			}	
		}
		
		
		///<summary>
		/// Fill an VList&lt;VwSKPoDokumentimaPoTipu&gt; From a DataTable
		///</summary>
		/// <param name="dataTable">the DataTable that hold the data.</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pagelen">number of row.</param>
		///<returns><see chref="VList<VwSKPoDokumentimaPoTipu>"/></returns>
		protected static VList&lt;VwSKPoDokumentimaPoTipu&gt; Fill(DataTable dataTable, VList<VwSKPoDokumentimaPoTipu> rows, int start, int pagelen)
		{
			int recordnum = 0;
			
			System.Collections.IEnumerator dataRows =  dataTable.Rows.GetEnumerator();
			
			while (dataRows.MoveNext() && (pagelen != 0))
			{
				if(recordnum >= start)
				{
					DataRow row = (DataRow)dataRows.Current;
				
					VwSKPoDokumentimaPoTipu c = new VwSKPoDokumentimaPoTipu();
					c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
					c.Kolona = (Convert.IsDBNull(row["Kolona"]))?string.Empty:(System.String)row["Kolona"];
					c.Opis = (Convert.IsDBNull(row["Opis"]))?string.Empty:(System.String)row["Opis"];
					c.Suma = (Convert.IsDBNull(row["Suma"]))?0:(System.Decimal?)row["Suma"];
					c.IDDokument = (Convert.IsDBNull(row["IDDokument"]))?(int)0:(System.Int32)row["IDDokument"];
					c.Grupna = (Convert.IsDBNull(row["Grupna"]))?string.Empty:(System.String)row["Grupna"];
					c.AcceptChanges();
					rows.Add(c);
					pagelen -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		*/	
						
		///<summary>
		/// Fill an <see cref="VList&lt;VwSKPoDokumentimaPoTipu&gt;"/> From a DataReader.
		///</summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Start row</param>
		/// <param name="pageLength">number of row.</param>
		///<returns>a <see cref="VList&lt;VwSKPoDokumentimaPoTipu&gt;"/></returns>
		protected VList<VwSKPoDokumentimaPoTipu> Fill(IDataReader reader, VList<VwSKPoDokumentimaPoTipu> rows, int start, int pageLength)
		{
			int recordnum = 0;
			while (reader.Read() && (pageLength != 0))
			{
				if(recordnum >= start)
				{
					VwSKPoDokumentimaPoTipu entity = null;
					if (DataRepository.Provider.UseEntityFactory)
					{
						entity = EntityManager.CreateViewEntity<VwSKPoDokumentimaPoTipu>("VwSKPoDokumentimaPoTipu",  DataRepository.Provider.EntityCreationalFactoryType); 
					}
					else
					{
						entity = new VwSKPoDokumentimaPoTipu();
					}
					entity.ID = (System.Int32)reader["ID"];
					//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
					entity.Kolona = (System.String)reader["Kolona"];
					//entity.Kolona = (Convert.IsDBNull(reader["Kolona"]))?string.Empty:(System.String)reader["Kolona"];
					entity.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (System.String)reader["Opis"];
					//entity.Opis = (Convert.IsDBNull(reader["Opis"]))?string.Empty:(System.String)reader["Opis"];
					entity.Suma = reader.IsDBNull(reader.GetOrdinal("Suma")) ? null : (System.Decimal?)reader["Suma"];
					//entity.Suma = (Convert.IsDBNull(reader["Suma"]))?0:(System.Decimal?)reader["Suma"];
					entity.IDDokument = (System.Int32)reader["IDDokument"];
					//entity.IDDokument = (Convert.IsDBNull(reader["IDDokument"]))?(int)0:(System.Int32)reader["IDDokument"];
					entity.Grupna = reader.IsDBNull(reader.GetOrdinal("Grupna")) ? null : (System.String)reader["Grupna"];
					//entity.Grupna = (Convert.IsDBNull(reader["Grupna"]))?string.Empty:(System.String)reader["Grupna"];
					entity.AcceptChanges();
					rows.Add(entity);
					pageLength -= 1;
				}
				recordnum += 1;
			}
			return rows;
		}
		
		
		/// <summary>
		/// Refreshes the <see cref="VwSKPoDokumentimaPoTipu"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VwSKPoDokumentimaPoTipu"/> object to refresh.</param>
		protected void RefreshEntity(IDataReader reader, VwSKPoDokumentimaPoTipu entity)
		{
			reader.Read();
			entity.ID = (System.Int32)reader["ID"];
			//entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
			entity.Kolona = (System.String)reader["Kolona"];
			//entity.Kolona = (Convert.IsDBNull(reader["Kolona"]))?string.Empty:(System.String)reader["Kolona"];
			entity.Opis = reader.IsDBNull(reader.GetOrdinal("Opis")) ? null : (System.String)reader["Opis"];
			//entity.Opis = (Convert.IsDBNull(reader["Opis"]))?string.Empty:(System.String)reader["Opis"];
			entity.Suma = reader.IsDBNull(reader.GetOrdinal("Suma")) ? null : (System.Decimal?)reader["Suma"];
			//entity.Suma = (Convert.IsDBNull(reader["Suma"]))?0:(System.Decimal?)reader["Suma"];
			entity.IDDokument = (System.Int32)reader["IDDokument"];
			//entity.IDDokument = (Convert.IsDBNull(reader["IDDokument"]))?(int)0:(System.Int32)reader["IDDokument"];
			entity.Grupna = reader.IsDBNull(reader.GetOrdinal("Grupna")) ? null : (System.String)reader["Grupna"];
			//entity.Grupna = (Convert.IsDBNull(reader["Grupna"]))?string.Empty:(System.String)reader["Grupna"];
			reader.Close();
	
			entity.AcceptChanges();
		}
		
		/*
		/// <summary>
		/// Refreshes the <see cref="VwSKPoDokumentimaPoTipu"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VwSKPoDokumentimaPoTipu"/> object.</param>
		protected static void RefreshEntity(DataSet dataSet, VwSKPoDokumentimaPoTipu entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.ID = (Convert.IsDBNull(dataRow["ID"]))?(int)0:(System.Int32)dataRow["ID"];
			entity.Kolona = (Convert.IsDBNull(dataRow["Kolona"]))?string.Empty:(System.String)dataRow["Kolona"];
			entity.Opis = (Convert.IsDBNull(dataRow["Opis"]))?string.Empty:(System.String)dataRow["Opis"];
			entity.Suma = (Convert.IsDBNull(dataRow["Suma"]))?0:(System.Decimal?)dataRow["Suma"];
			entity.IDDokument = (Convert.IsDBNull(dataRow["IDDokument"]))?(int)0:(System.Int32)dataRow["IDDokument"];
			entity.Grupna = (Convert.IsDBNull(dataRow["Grupna"]))?string.Empty:(System.String)dataRow["Grupna"];
			entity.AcceptChanges();
		}
		*/
			
		#endregion Helper Functions
	}//end class

	#region VwSKPoDokumentimaPoTipuFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwSKPoDokumentimaPoTipu"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwSKPoDokumentimaPoTipuFilterBuilder : SqlFilterBuilder<VwSKPoDokumentimaPoTipuColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwSKPoDokumentimaPoTipuFilterBuilder class.
		/// </summary>
		public VwSKPoDokumentimaPoTipuFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwSKPoDokumentimaPoTipuFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwSKPoDokumentimaPoTipuFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwSKPoDokumentimaPoTipuFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwSKPoDokumentimaPoTipuFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwSKPoDokumentimaPoTipuFilterBuilder

	#region VwSKPoDokumentimaPoTipuParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;EntityColumn&gt;"/> class
	/// that is used exclusively with a <see cref="VwSKPoDokumentimaPoTipu"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class VwSKPoDokumentimaPoTipuParameterBuilder : ParameterizedSqlFilterBuilder<VwSKPoDokumentimaPoTipuColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the VwSKPoDokumentimaPoTipuParameterBuilder class.
		/// </summary>
		public VwSKPoDokumentimaPoTipuParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the VwSKPoDokumentimaPoTipuParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public VwSKPoDokumentimaPoTipuParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the VwSKPoDokumentimaPoTipuParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public VwSKPoDokumentimaPoTipuParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion VwSKPoDokumentimaPoTipuParameterBuilder
} // end namespace
